「Widthって、FrameworkElementクラスのメンバーで、Rectangleクラスなどのコントロールはこれを継承している。継承したクラスのメンバーは別口ってことだ」
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Animation;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
namespace MetroWidthAnimation001
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// このページがフレームに表示されるときに呼び出されます。
/// </summary>
/// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
/// プロパティは、通常、ページを構成するために使用します。</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var rect = MyRect;
var storyboard = new Storyboard();
var da = new DoubleAnimation();
Storyboard.SetTarget(da, rect);
Storyboard.SetTargetProperty(da, "Width");
da.EnableDependentAnimation = true;
da.From = rect.Width;
da.To = 0;
da.Duration = TimeSpan.FromSeconds(2);
storyboard.Children.Add(da);
storyboard.Completed += storyboard_Completed;
storyboard.Begin();
}
void storyboard_Completed(object sender, object e)
{
MyRect.Width = 1000;
}
}
}
<Page
x:Class="MetroWidthAnimation001.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MetroWidthAnimation001"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left"
Height="100" Stroke="Black" VerticalAlignment="Top" Width="1000"
Margin="235,264,0,0" x:Name="MyRect"/>
<Button Content="Button" HorizontalAlignment="Left"
VerticalAlignment="Top" Margin="330,439,0,0" Height="220" Width="701"
Click="Button_Click"/>
</Grid>
</Page>